package com.huli.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huli.domain.HuliAddress;
import com.huli.domain.OrderInfo;
import com.huli.mapper.HuliAddressMapper;
import com.huli.service.OrderInfoService;
import com.huli.mapper.OrderInfoMapper;
import com.huli.util.OrderNo;
import org.mockito.internal.matchers.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

import static java.math.BigDecimal.*;

/**
* @author 张庆阳
* @description 针对表【order_info(订单信息表)】的数据库操作Service实现
* @createDate 2025-03-16 13:03:39
*/
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo>
    implements OrderInfoService {
    @Autowired
    private OrderInfoMapper orderInfoMapper;


    @Override
    public void insertOrder(OrderInfo orderInfo) {//前端穿过来的
//        new一个orderinfo   里面有地址id   里面也有患者id  护理项目id   病例minio上传到并保存到caseImage字段   添加方法
        OrderInfo orderInfo1 = new OrderInfo();
        //设置地址id
        orderInfo1.setAddressId(orderInfo.getAddressId());
        //设置患者id
        orderInfo1.setPatientId(orderInfo.getPatientId());
        //设置护理项目id
        orderInfo1.setProjectId(orderInfo.getProjectId());
        //生成随机的订单编号
        String randomChar = OrderNo.getRandomChar(9);
        //设置订单编号
        orderInfo1.setOrderNo(randomChar);
        //生成随机的预约码
        String appCode = OrderNo.getRandomChar(8);
        //设置预约码
        orderInfo1.setAppointmentCode(appCode);
        //设置科室id
        orderInfo1.setDeptId(orderInfo.getDeptId());
        //设置金额
        orderInfo1.setOrderAmount(orderInfo.getOrderAmount());
        //设置日期
        orderInfo1.setServiceTime(orderInfo.getServiceTime());
        orderInfo1.setAppointmentTime(orderInfo.getAppointmentTime());
        //设置图片
        orderInfo1.setCaseImage(orderInfo.getCaseImage());
        //添加用户id
        orderInfo1.setUserId(orderInfo.getUserId());
        System.err.println(orderInfo1);
        //设置消息
        String message = "您接收到新的订单了，请及时派单";
        orderInfo1.setMessages(message);
        //设置消息状态
        orderInfo1.setMessageStatus(orderInfo.getMessageStatus());
        orderInfoMapper.insert(orderInfo1);
    }
//取消订单
    @Override
    public Integer deleteById(Integer id) {
       Integer deleteById =  orderInfoMapper.updateByAStatus(id);
        return deleteById;
    }
//查询订单列表
    @Override
    public List<OrderInfo> findAll(Integer userId) {
       List<OrderInfo> all = orderInfoMapper.findAll(userId);
        return all;
    }
//根据订单id查询
    @Override
    public OrderInfo findById(Integer id) {
      OrderInfo orderInfo = orderInfoMapper.findById(id);
      return orderInfo;
    }
//
    @Override
    public List<OrderInfo> findByOrderStatus(Integer orderStatus, Integer userId) {
       List<OrderInfo> Status = orderInfoMapper.findStatus(orderStatus ,userId);
       return Status;
    }
//删除订单
    @Override
    public Integer deleteByOrder(Integer id) {
        int deleteById = orderInfoMapper.deleteById(id);
        return deleteById;
    }

    @Override
    public String updateMessageStatus(Integer id, String messageStatus) {
       String messageStatus1 = orderInfoMapper.updateMessageStatus(id,messageStatus);
       return messageStatus1;
    }

    @Override
    public List<OrderInfo> updateMessageStatusll(OrderInfo orderInfo, String messageStatus) {
       List<OrderInfo> orderInfoList = orderInfoMapper.updateMessageStatusll(orderInfo,messageStatus);
       return orderInfoList;
    }
}




